<?php
/**
 * Created by PhpStorm.
 * 打赏相关操作
 * User: 王金鑫
 * Date: 2018/8/23
 * Time: 16:02
 */
namespace app\facescore\home;
use app\common\controller\Common;
use think\Db;

class Reward extends Common
{
    /**
     * 生成订单
     */
    public function setOrder(){
        /**
         * 校验登录状态
         */
        if(!checkLogin()){
            return json(['msg' => '没有登录']);
        }
       
      
        $data = [
            'content_id' => input('content_id'),
            'uid' => input('uid'),
            'money' => input('money'),
            'type' => input('type'), //支付类型 1 rmb 2 mag
            'imgs_id' => input('imgs_id'),
            'reward_type' => input('reward_type')
        ];

        $order = db::name('facescore_reward')->where($data)->find();
        if($order['id'] != null) {
            return json(['order_id' => $order['id'],'msg' => '该订单已经存在']);
        }else{
            $data = [
                'content_id' => input('content_id'),
                'uid' => input('uid'),
                'money' => input('money'),
                'create_time' => date('Y-m-d H:i:s'),
                'type' => input('type'), //支付类型 1 rmb 2 mag
                'imgs_id' => input('imgs_id'),
                'reward_type' => input('reward_type')
            ];
             Db::name('facescore_reward')->insert($data);
            //返回订单id
            return json(['order_id' => Db::name('facescore_reward')->getLastInsID()]);
        }
        
    }



}